package com.neu.controller;

import com.neu.dto.BookDTO;
import com.neu.service.BookService;
import com.neu.utils.ResultModel;
import com.neu.vo.BookVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//import org.springframework.data.redis.core.RedisTemplate;

@RestController
@RequestMapping("/book")
@RefreshScope
public class BookController {

    @Autowired
    BookService bookService;
//    @Autowired
//    RedisTemplate redisTemplate;

    @PostMapping("/product/{productId}")
    public ResultModel add(@PathVariable("productId") Integer productId){
        ResultModel resultModel = new ResultModel();

        //根据商品id获取商品的信息
        bookService.add(productId);
        resultModel.setMsg("下单成功,商品id="+productId);
        return resultModel;
    }

    @GetMapping
    public ResultModel<List<BookVO>> find(BookDTO bookDTO){
        ResultModel<List<BookVO>> resultModel = new ResultModel<>();

        List<BookVO> bookVOList = bookService.find(bookDTO);

        resultModel.setData(bookVOList);
        resultModel.setMsg("获取订单成功");
        return resultModel;
    }




}
